﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OneMake.Model
{
    //来访时段分析
    public class report_visit_period_stat
    {
        [MapToExcel(ColumnName = "品牌")]
        public string brand { get; set; }

        [MapToField(FieldName = "日期")]
        public DateTime stat_datetime { get; set; }

        [MapToExcel(ColumnName = "小时段")]
        public string hour_sect { get; set; }

        [MapToExcel(ColumnName = "总来访人数")]
        public int n_person { get; set; }

        [MapToExcel(ColumnName = "总来访人数占比")]
        public double per_person { get; set; }

        [MapToExcel(ColumnName = "总来访次数")]
        public double total_visit { get; set; }
    }

    partial class ReportHelper
    {
        public List<report_visit_period_stat> get_report_visit_period_stat(string brand, DateTime beginTime, DateTime endTime)
        {
            System.Diagnostics.Debug.Assert(beginTime <= endTime);

            var db = new PetaPoco.Database("mysql" + UserSession.Network);
            string sql = "select * from mf_m_lfsd where brand=@0 and (stat_datetime between @1 and @2)";
            List<report_visit_period_stat> reports = db.Query<report_visit_period_stat>(sql, brand, beginTime, endTime).ToList();
            return reports;
        }

        public List<string> get_report_visit_period_stat_brands()
        {
            var db = new PetaPoco.Database("mysql" + UserSession.Network);
            string sql = "select brand from mf_m_lfsd group by brand";
            IEnumerable<string> brands = db.Query<string>(sql);
            return brands.ToList<string>();
        }
    }
}
